import {createStore} from 'vuex'
import {getLocalStorageObject, getLocalStorageStr} from '../utils/index.js'

const store = createStore({
    state: {
        token: '',
        userInfo: getLocalStorageObject('userInfo')
    },
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token
        },
        SET_USERINFO: (state, userInfo) => {
            state.userInfo = userInfo
            localStorage.setItem('userInfo',JSON.stringify( userInfo))
        }
    },
    actions: {
        // 登录
        Login({commit}, userInfo) {
            commit('SET_USERINFO', userInfo)
        },
        logout({commit}) {
            commit('SET_USERINFO', {user:''})
        }
    }
})
export default store
